<?
	global $kam_admin, $FullUrl, $arr, $table_edit, $elements, $config_xml_list, $lg;
    $edit_url = 'admin-pro.html?do='.$table_edit.'&act=edit_full&id=';
    $delete_url = 'admin-pro.html?do='.$table_edit.'&act=del&id=';
    $deletelist_url = 'admin-pro.html?do='.$table_edit.'&act=dellist';
    $showlist_url = 'admin-pro.html?do='.$table_edit.'&act=show';
    $hidelist_url = 'admin-pro.html?do='.$table_edit.'&act=hide';
    $changeactive_url='admin-pro.html?do='.$table_edit.'&&act=changeactive&page='.(isset($_GET['page'])?$_GET['page']:'1').'&id=';
    $changehome_url='admin-pro.html?do='.$table_edit.'&act=changehome&page='.(isset($_GET['page'])?$_GET['page']:'1').'&id=';
    $changeorder_url = 'admin-pro.html?do='.$table_edit.'&act=order';
	$changesilder_url = 'admin-pro.html?do=image_post_silder&act=list_img_pro&id=';
	$export_url = 'admin-pro.html?do='.$table_edit.'&act=export_full';
?>
<?
	global $title1, $title2, $staffs;
	$title1 = array('name', 'short', 'status', 'nguoithuchien_id', 'nguoiyeucau_id', 'nguoiquanly_id', 'date_begin', 'date_end');
	$title2 = array('Công việc', 'Mô tả ngắn', 'Tình trạng', 'Người thực hiện', 'Người yêu cầu', 'Người quản lý','Start', 'End');	
	
?>
<div class="contentcontainer">
  <div class="headings altheading">
    <h2>Danh sách sản phẩm</h2>
    <a href="<?=$FullUrl.'/'.$export_url?>">Export Data</a>
  </div>
   <div>
  	<?php
    $cc = new Categories();
    $cid = isset($_GET['cid'])?$_GET['cid']:'0';
    if(isset($_GET['cid']))
        $cid = $_GET['cid'];
    $tree = $cc->admin_tree_filter_change('1',$cid,'1', 'product','','ChangeFindCidList');
    echo $tree;
?>
  </div>
  <form name="f" id="f" method="post" action="<?=$deletelist_url?><?=isset($_GET['cid'])?'&cid='.$_GET['cid']:''?><?=isset($_GET['page'])?'&page='.$_GET['page']:''?>" onsubmit="return confirm('Are You Sure?');">
    <div class="contentbox">
      <table width="100%">
        <thead>
          <tr> 
          	<th>Tiến Độ</th>
            <?
          	for($i = 0; $i < count($arr);$i++)
            {
            	$name_label = $arr[$i]['column_name'];
                //echo "lan thu [".$i."]".$name_label."<br/>";
                if($config_xml_list[$i]=='1')
                {
					if($name_label == 'id')
                    {
                    ?>
                <th>STT</th>
                <?
                    }				
					else if($name_label == 'num')
                    {
                    ?>
                <th><input type="submit" value="Change Order" class="btn" onclick="ChangeAction('<?=$changeorder_url?>');return false;"/></th>
                <?
                    }					
					else if($name_label == 'img')
                    {
                    ?>                    
                <th>Hình</th>
                <?
                    }
					else if($name_label == 'active')
                    {
                    ?>
                <th>Hiện/Ẩn</th>
                <?
                    }
                     else
                    {
              ?>
                <th><?=replaceArrayNames($name_label)?></th>
                <?
                    }
                 }   
                    ?>
            <?  
          	}
          ?>
            <!--<th>Silder Image</th>
          	<th>Link</th>-->
            <th>Edit</th>
            <th>Delete</th>
            <th><input name="" type="checkbox" value="" onclick="checkAll();return false;" id="all"/></th>
          </tr>
        </thead>
        <tbody>
          <?
        	for($i = 0; $i < count($elements); $i++)
            {
            	//print_r($elements);
            	$element = $elements[$i];
                $element_id = $element['id'];
                $element_num = $element['num'];
                //$element_home = $element['home'];
                $element_show = $kam_admin.'/images/icons/icon_'.(($element['active']=='0')?'un':'').'approve.png';
				$element_star = $kam_admin.'/images/icons/star_rating_full.png';
                //$element_show_home = $kam_admin.'/images/icons/'.(($element['home']=='0' || $element['home']=='')?'un':'').'active-home.png';
        ?>
          <tr <?=($i%2) == 0 ? 'class="alt"' : ''?>>
            <td><img src="<?=$element_star?>" width="24px" /></td>
            <?
                	for($j = 0; $j < count($arr); $j++)
                    {
                    	$name_data = $arr[$j]['column_name'];
                        if($config_xml_list[$j]=='1')
                		{
                            if($name_data == 'num')
                            {
                            ?>
                                <td><input type="text" id="smallbox" class="inputbox smallbox2" value="<?=$element_num?>" name="ordering[]" onkeypress="return OnlyNumber(event)"/><input type="hidden" name="id[]" value="<?=$element_id?>" /></td>       
                            <?
                            }
                            else if($name_data == 'img')                        
                            {?>
                            	<td><img src="<?=$FullUrl.'/'.$element[$arr[$j]['column_name']]?>" alt="Hình Ảnh" width="100px" /></td>
                            <?}
                            else if($name_data == 'active')                        
                            {
                            ?>
                                <td><a href="<?=$changeactive_url.$element_id?>&current=<?=$element[$arr[$j]['column_name']]?>" title=""><img src="<?=$element_show?>" alt="Approve/Unapprove" title="Click vào để thay đổi"/></a> </td>
                            <?
                            }
                            else if($name_data == 'home')                        
                            {
                            ?>
                                <td><a href="<?=$changehome_url.$element_id?>&current=<?=$element[$arr[$j]['column_name']]?>" title=""><img src="<?=$element_show_home?>" alt="Approve/Unapprove" title="Click vào để thay đổi" height="48"/></a> </td>
                            <?
                            }
							 else if($name_data == 'name_vn' || $name_data == 'diengiai')
                            {?>
                            	<td style="text-align:left;"><a href="<?=$edit_url.$element_id?>" title="" style="text-decoration:none; color:#00F;"><?=$element[$arr[$j]['column_name']]?></a></td>                    
                            <?
                            }
							else if($name_data == 'nguoithuchien_id' || $name_data == 'nguoiquanly_id' ||$name_data == 'nguoiyeucau_id')
                            {?>
                            	<td style="text-align:left;">	                                					
								<?
                                $arr2 = checkStaff($element[$arr[$j]['column_name']]);
								if($arr2 !='-1')									
								{
									echo $arr2['first_name']. " ". $arr2['last_name'];
								}
                                
                                ?>
                                
                                </td>                    
                            <?
                            }
							 else if($name_data == 'price' || $name_data == 'money_input' || $name_data == 'money_output' || $name_data == 'sodu')
                            {?>
                            	<td style="text-align:right;"><?=number_format($element[$arr[$j]['column_name']])?></td>                    
                            <?
                            }
                            else
                            {
                            ?>
                <td><?=$element[$arr[$j]['column_name']]?></td>
                            <?
                            }
                        }   
                            ?>
            <?   
                    }
                ?>
                <!--<td><a href="<?=$changesilder_url.$element_id?>" title=""><img src="<?=$kam_admin?>/images/icons/pictures.png" alt="Edit" title="Click vào đây để chỉnh sửa ảnh" width="64"/></a></td>
                <td><a href="<?=GetArtLinkCMSFull($elements[$i],$lg)?>" target="_blank"><img src="<?=$kam_admin?>/images/preview.png" alt="Edit" title="Xem bài viết"/></a></td>-->   
            <td><a href="<?=$edit_url.$element_id?>" title=""><img src="<?=$kam_admin?>/images/icons/icon_edit.png" alt="Edit" title="Click vào đây để chỉnh sửa"/></a></td>
            <td><a href="<?=$delete_url.$element_id?>" title=""><img src="<?=$kam_admin?>/images/icons/icon_delete.png" alt="Delete" title="Click vào đây để xóa"/></a></td>
            <td><input type="checkbox" value="<?=$element_id?>" name="iddel[]" id="check<?=$i?>"/></td>
          </tr>
          <?
        	}
        ?>
        </tbody>
      </table>
      <div class="extrabottom">
        <div class="bulkactions">
          <ul>
            <li><a onclick="ChangeAction('<?=$showlist_url?>');return false;" href=""><img src="<?=$kam_admin?>/images/icons/icon_approve.png" alt="Approve" /> Show</a></li>
            <li><a onclick="ChangeAction('<?=$hidelist_url?>');return false;" href=""><img src="<?=$kam_admin?>/images/icons/icon_unapprove.png" alt="Unapprove" /> Hide</a></li>
            <li><a onclick="ChangeAction('<?=$deletelist_url?>');return false;" href=""><img src="<?=$kam_admin?>/images/icons/icon_delete.png" alt="Delete" /> Remove</a></li>
          </ul>
        </div>
      </div>
      <?=$plpage?>
      <div style="clear: both;"></div>
    </div>
  </form>
</div>
<script>
function ChangeAction(str){
	if(confirm("Are You Sure?"))
	{
		document.f.action = str;
		document.f.submit();
	}
}
function checkAll()
{
	if(document.f.all.checked == true)
	{
		for(var i=0;i<20;i++)
		{
			
			document.getElementById("check"+i).checked = true;
		}
	}
	else
	{
		for(var i=0;i<20;i++)
		{
			
			document.getElementById("check"+i).checked = false;
		}
	}
	
}
</script> 
